//
// Created by Tan Ke on 2023/12/30.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>


bool isValid(char* s)
{
    char queue[10000] = {0};
    memset(queue, 0, 10000);
    int queueLen = 0;

    for (int i = 0; i < strlen(s); i ++) {
        if (s[i] == '(' || s[i] == '{' || s[i] == '[') {
            queue[queueLen] = s[i];
            queueLen += 1;
        }
        if (s[i] == ')' || s[i] == '}' || s[i] == ']') {
            if (queueLen == 0) {
                return false;
            }
            if (s[i] == ')' && queue[queueLen-1] != '(') {
                return false;
            }
            if (s[i] == '}' && queue[queueLen-1] != '{') {
                return false;
            }
            if (s[i] == ']' && queue[queueLen-1] != '[') {
                return false;
            }
            queue[queueLen-1] = 0;
            queueLen -= 1;
        }
    }

    if (queueLen != 0) {
        return false;
    }
    return true;
}

int main(void)
{
    return 0;
}
